<template>
  <el-card>
    <div class="head">
      <el-button color="#1baeae" :icon="Plus" @click="changeDisable(0)"
        >解除禁用</el-button
      >
      <el-button color="#f56c6c" :icon="Delete" @click="changeDisable(1)"
        >禁用账户</el-button
      >
    </div>
    <el-table
      @selection-change="changSatus"
      :data="tableData"
      style="width: 100%;margin: 20px 0;"
    >
      <el-table-column type="selection" />
      <el-table-column prop="nickName" label="昵称" />
      <el-table-column prop="loginName" label="登录名" />
      <el-table-column prop="lockedFlag" label="身份状态">
        <template #default="scope">
          <p style="color: #008000" v-if="scope.row.lockedFlag == 0">正常</p>
          <p style="color: #f00" v-if="scope.row.lockedFlag == 1">禁用</p>
        </template>
      </el-table-column>
      <el-table-column prop="isDeleted" label="是否注销">
        <template #default="scope">
          <p style="color: #008000" v-if="scope.row.lockedFlag == 0">正常</p>
          <p style="color: #f00" v-if="scope.row.lockedFlag == 1">正常</p>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="注册时间" />
    </el-table>
    <div class="pagination">
      <el-pagination
        v-model:current-page="data.pageNumber"
        v-model:page-size="data.pageSize"
        :page-sizes="[10, 20, 30, 40]"
        :background="true"
        layout="prev, pager, next"
        :total="totalCount"
        @size-change="getList"
        @current-change="getList"
      />
    </div>
  </el-card>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted } from "vue";
import { useRoute, useRouter } from "vue-router";
import { api } from "../../../api/api";
import { Plus, Delete } from "@element-plus/icons-vue";
import { ElMessage } from "element-plus";
const route = useRoute();
const router = useRouter();
const tableData = ref([]);
const totalCount = ref(0);
const data = reactive({
  pageSize: 10,
  pageNumber: 1,
});
async function getList() {
  const res: any = await api.getUsersListApi(data);
  tableData.value = res.data.list;
  totalCount.value = res.data.totalCount;
}
onMounted(() => {
  getList();
});
// 表格复选框状态
const selectionArr = ref<number[]>([]);
function changSatus(e: any) {
  e.forEach((item: any) => {
    selectionArr.value.push(item.userId);
  });
}
async function changeDisable(status: number) {
  const res: any = await api.disableUsersApi({
    status: status,
    ids: selectionArr.value,
  });
  if (res.resultCode == 200) {
    switch (status) {
      case 0:
        ElMessage.success("解除成功");
        break;
      case 1:
        ElMessage.success("禁用成功");
        break;
    }
    getList();
  }
}
</script>

<style lang="scss" scoped>
.head {
  .el-button {
    color: #fff;
  }
}
.pagination {
  width: 100%;
  display: flex;
  margin: 20px 0;
  justify-content: center;
  align-items: center;
}
</style>
